package com.hehe.gateway.auth;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;

public class AutConfiguration extends ResourceServerConfigurerAdapter {
	@Value("security.oauth2.resource.token-info-uri")
	private String checkTokenEndpointUrl;
    @Override
    public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
          .antMatchers("/auth/**")
          .permitAll()
          .antMatchers("/**")
      .authenticated().and().csrf().disable();
    }
    
	@Override
	public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
		resources.tokenServices(tokenServices());
	}
	
	public ResourceServerTokenServices tokenServices() {
		RemoteTokenServices tokenServices = new RemoteTokenServices();
		tokenServices.setCheckTokenEndpointUrl(checkTokenEndpointUrl);
		return tokenServices;
		
	}
    
}